package com.ldg.manager.controller;

import java.util.Arrays;
import java.util.Map;

import com.ld.utils.PageUtils;
import com.ld.pojo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ldg.manager.entity.SellerEntity;
import com.ldg.manager.service.SellerService;




/**
 * 商家管理
 *
 * @author LD
 * @email 419631142@qq.com
 * @date 2022-09-12 18:39:32
 */
@RestController
@RequestMapping("seller")
public class SellerController {
    @Autowired
    private SellerService sellerService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sellerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{sellerId}")
    public R info(@PathVariable("sellerId") String sellerId){
        SellerEntity seller = sellerService.getById(sellerId);

        return R.ok().put("seller", seller);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SellerEntity seller){
        sellerService.save(seller);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody SellerEntity seller){
        sellerService.updateById(seller);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody String[] sellerIds){
        sellerService.removeByIds(Arrays.asList(sellerIds));

        return R.ok();
    }

    /**
     * 状态审核
     * @param sellerId
     * @param status
     * @return
     */
    @GetMapping("updateStatus/{sellerId}/{status}")
    public R updateStatus(@PathVariable String sellerId,@PathVariable String status){
        sellerService.updateStatus(sellerId,status);
        return R.ok();
    }

}
